<template>
  <el-header class="btn-bar">
    <slot></slot>
    <el-button v-if="uploadJson" type="text" @click="$emit('uploadJson')">
      <template #icon>
        <SvgIcon name="upload" />
      </template>
      导入JSON
    </el-button>
    <el-button v-if="clearable" type="text" @click="$emit('clearable')">
      <template #icon>
        <SvgIcon name="clearable" />
      </template>
      清空
    </el-button>
    <el-button v-if="preview" type="text" @click="$emit('preview')">
      <template #icon>
        <SvgIcon name="preview" />
      </template>
      预览
    </el-button>
    <el-button v-if="generateJson" type="text" @click="$emit('generateJson')">
      <template #icon>
        <SvgIcon name="generate-json" />
      </template>
      生成JSON
    </el-button>
    <el-button v-if="generateCode" type="text" @click="$emit('generateCode')">
      <template #icon>
        <SvgIcon name="generate-code" />
      </template>
      生成代码
    </el-button>
  </el-header>
</template>

<script setup lang="ts">
import { useAttrs } from 'vue';
import SvgIcon from '@/components/SvgIcon/index.vue';

defineEmits(['uploadJson', 'clearable', 'preview', 'generateJson', 'generateCode']);

const { uploadJson, clearable, preview, generateJson, generateCode } = useAttrs() as {
  uploadJson?: boolean;
  clearable?: boolean;
  preview?: boolean;
  generateJson?: boolean;
  generateCode?: boolean;
};
</script>
